//======================================================================
/// COPYRIGHT MorningCoreTech CO.,LTD
/// @file        PUCCH_RE_Mapper_fix.cpp
/// @brief       This function performs PUCCH Resource Mapping Proc
/// @author          cuiyuping
/// @param [IN]	     SimParam		       Input  Parameter .
/// @param [IN]	     PUCCH_DmrsRes_Op	   DMRS
/// @param [IN]	     PUCCH_DFT_Op		   DATA.     
/// @param [OUT]	 PUCCH_ResOp	   PUCCH DMRS and Data Resource Mapping Result.     
/// @par History
/// -
///       Date|       Author|        Version|        DESCRIPTION
/// ----------|-------------|---------------|-------------------
/// 2022-10-20|   cuiyuping |          0.0.1|            created
//======================================================================

#include "../../../CommLib_FxpC/lib_arith_N.h"
#include "../../../CommLib_FltC/GlobalVarDef.h"
#include "../common/head/NR_UL_macro.h"
#include "ue_tx_pucch_remapper_fix.h"
#include "ue_tx_pucch_fe_fix.h"


void  PUCCH_RE_Mapper_fix
(
IN stULParamTable *SimParam,
IN   cmplx_frN *PUCCH_Dmrs_Op[PUCCH_DMRS_MAX_NUM],
IN   cmplx_frN *PUCCH_DFT_Op[PUCCH_DATA_MAX_NUM],
OUT  cmplx_frN *PUCCH_ResOp[MAXSYMNUM]
)
{
    /*variables definition*/
    int   iSym,k, SymIdx, ReOffset;

	set_rnd_mode_floor();
		
	ReOffset = SC_PER_RB*SimParam->PUCCH_RB_Index[0];
    /*fill up data*/
    for (iSym = 0; iSym <SimParam->DataSymNum; iSym++)//for each symbol
    {
		SymIdx = SimParam->FirstSym_Pos + SimParam->DataSymPos[iSym];
		for (k = 0; k< SC_PER_RB*SimParam->PUCCH_RB_Num; k++)
        {
			if (1 == SimParam->intra_slot_hopping)
			{
				if (iSym < SimParam->DataSymFirstHop)
				{
					ReOffset = SC_PER_RB * SimParam->PUCCH_RB_Index[0];
				}
				else
				{
					ReOffset = SC_PER_RB * SimParam->PUCCH_RB_Index[1];
				}
			}

            if (PUCCH_FORMAT_0 == SimParam->PUCCH_Format)
            {                   

				PUCCH_ResOp[SymIdx][ReOffset + k].re = sat_fr1xN_bitwidth(((mult_fr1xM(PUCCH_DFT_Op[iSym][k].re, SimParam->BetaPUCCH_Fix)) >> 13),14);//Q(N,1)
				PUCCH_ResOp[SymIdx][ReOffset + k].im = sat_fr1xN_bitwidth(((mult_fr1xM(PUCCH_DFT_Op[iSym][k].im, SimParam->BetaPUCCH_Fix)) >> 13),14);

            }
            else //(PUCCH_FORMAT_1 == SimParam->PUCCH_Format)
            {                   

				PUCCH_ResOp[SymIdx][ReOffset + k].re = sat_fr1xN_bitwidth(((mult_fr1xM(PUCCH_DFT_Op[iSym][k].re, SimParam->BetaPUCCH_Fix)) >> 14), 14); ;//Q(N,5)
				PUCCH_ResOp[SymIdx][ReOffset + k].im = sat_fr1xN_bitwidth(((mult_fr1xM(PUCCH_DFT_Op[iSym][k].im, SimParam->BetaPUCCH_Fix)) >> 14), 14); ;//Q(N,5)
            }
        }
    }

  

	ReOffset = SC_PER_RB * SimParam->PUCCH_RB_Index[0];
	/*fill up data*/
	for (iSym = 0; iSym < SimParam->DmrsSymNum; iSym++)//for each symbol
	{
		SymIdx = SimParam->FirstSym_Pos + SimParam->DmrsSymPos[iSym];
		for (k = 0; k < SC_PER_RB*SimParam->PUCCH_RB_Num; k++)
		{
			if (1 == SimParam->intra_slot_hopping)
			{
				if (iSym < SimParam->DmrsSymFirstHop)
				{
					ReOffset = SC_PER_RB * SimParam->PUCCH_RB_Index[0];
				}
				else
				{
					ReOffset = SC_PER_RB * SimParam->PUCCH_RB_Index[1];
				}
			}

			if (PUCCH_FORMAT_0 == SimParam->PUCCH_Format)
			{

				PUCCH_ResOp[SymIdx][ReOffset + k].re = sat_fr1xN_bitwidth(((mult_fr1xM(PUCCH_Dmrs_Op[iSym][k].re, SimParam->BetaDMRSPUCCH_Fix)) >> 14),14);//Q(N,1)
				PUCCH_ResOp[SymIdx][ReOffset + k].im = sat_fr1xN_bitwidth(((mult_fr1xM(PUCCH_Dmrs_Op[iSym][k].im, SimParam->BetaDMRSPUCCH_Fix)) >> 14),14);

			}
			else //(PUCCH_FORMAT_1 == SimParam->PUCCH_Format)
			{
				PUCCH_ResOp[SymIdx][ReOffset + k].re = sat_fr1xN_bitwidth(((mult_fr1xM(PUCCH_Dmrs_Op[iSym][k].re, SimParam->BetaDMRSPUCCH_Fix)) >> 14), 14); ;//Q(N,4)
				PUCCH_ResOp[SymIdx][ReOffset + k].im = sat_fr1xN_bitwidth(((mult_fr1xM(PUCCH_Dmrs_Op[iSym][k].im, SimParam->BetaDMRSPUCCH_Fix)) >> 14), 14); ;//Q(N,4)

			}
		}
	}


}



